package com.sphd.emanu.fragment.details.idetailitem;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sphd.emanu.R;
import com.sphd.emanu.adapter.MyViewPagerAdapter;
import com.sphd.emanu.config.Constant;
import com.sphd.emanu.fragment.details.detailca.DetailCAFragment;
import com.sphd.emanu.fragment.details.detailcb.DetailCBFragment;
import com.sphd.emanu.mvp.MVPBaseFragment;
import com.sphd.emanu.pojo.bank.AccountDetailsBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class IDetailItemFragment extends MVPBaseFragment<IDetailItemContract.View, IDetailItemPresenter> implements IDetailItemContract.View {
    @BindView(R.id.out_in_money)
    TextView outInMoney;
    @BindView(R.id.details_tablayout)
    TabLayout tabs;
    @BindView(R.id.vp_Fragment_pager)
    ViewPager vpFragmentPager;
    Unbinder unbinder;
    private AccountDetailsBean accountDetailsBean;
    Bundle bundle;
    DetailCAFragment detailCA;
    DetailCBFragment detailCB;
    private List<Fragment> list_fragment;
    MyViewPagerAdapter myViewPagerAdapter;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_detail_i;
    }

    @Override
    protected void initView() {
        unbinder = ButterKnife.bind(this, rootView);
        bundle = getArguments();
        accountDetailsBean = (AccountDetailsBean) bundle.getSerializable(Constant.ACCOUNT_DETAILS_BEAN);
        initAdapter();

        if (accountDetailsBean.getDebit() > 0) {//支出大于0
            outInMoney.setText("-" + accountDetailsBean.getDebit());
        } else {
            outInMoney.setText("+" + accountDetailsBean.getCredit());
        }
        setUserVisibleHint(true);
    }
    private void initAdapter() {
        detailCA = new DetailCAFragment();
        detailCB = new DetailCBFragment();
        //将fragment装进列表中
        list_fragment = new ArrayList<>();
        detailCA.setArguments(bundle);
        detailCB.setArguments(bundle);
        list_fragment.add(detailCA);
        list_fragment.add(detailCB);
        String titles[] = {"报销明细", "审批流程"};
        myViewPagerAdapter = new MyViewPagerAdapter(context, getChildFragmentManager(), list_fragment, titles);
        tabs.setupWithViewPager(vpFragmentPager);
        vpFragmentPager.setAdapter(myViewPagerAdapter);
    }
    @Override
    protected void initData() {

    }



    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
